<% layout( 'admin_layout') -%>



    <div id="wrapper" class="wrapper">

        <nav class="navbar" style="background-color: #3BBFB4;">

            <div class="container-fluid">

                <div class="raw">

                    <div class="col-sm-6 col-xs-6">

                        <h3 style="margin-left:50px;color:#fff;">全局设置</h3>

                    </div>

                    <div class="col-sm-6 col-xs-6">



                        <div class="box" style="float:right;margin-top: 10px;margin-right:5%;">

                            <div class="demo  btn btn-success">



                                <a style="color:#fff" onclick="save()">保存</a>

                            </div>





                        </div>
                        <!-- HBox end -->

                    </div>

                </div>

            </div>

        </nav>

    </div>


    <section class="content-wrap">

        <div class="container">

            <div class="raw" id="bodycontent">

                <main id="content" class="main-content" role="main">





                    <div>

                        <form role="form" class="col-sm-offset-1 col-sm-7">

                            <div class="form-group">

                                <label>博客名称:</label>

                                <input type="text" class="form-control" id="name">

                                <span class="help-block">为你的博客取一个响亮的名字<span>

                </div>

                <div class="form-group">

                  <label>博客简介:</label>

                  <textarea class="form-control" rows="5" id="description"></textarea>

                  <span class="help-block">简单介绍一下你的博客</span>

                            </div>

                            <hr/>
                            <div class="form-group">
                                <label>博客 Logo</label><br/>
                                <button type="button" class="btn btn-success" data-toggle="modal" data-target="#logoModal">上传图片</button>
                                <span class="help-block">为博客设置一个 logo</span>
                            </div>
                            <div class="form-group">
                                <label>博客封面图</label><br/>
                                <button type="button" class="btn btn-success" data-toggle="modal" data-target="#coverModal">上传图片</button>
                                <span class="help-block">为你的博客设置一个个性的封面图</span>
                            </div>
                        </form>

                    </div>

                </main>

            </div>

    </section>

    </div>
    <!-- 模态框（Modal） -->

    <div class="modal fade" id="logoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

        <div class="modal-dialog">

            <div class="modal-content">

                <div class="modal-header">

                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

                    <h4 class="modal-title" id="myModalLabel">

					请输入博客logo图片地址

					</h4>

                </div>

                <div class="modal-body">

                    <input id="logoin" type="text" class="form-control" placeholder="http://">
                    <!--this is a upload file test!-->
                    <div>
                        <form enctype="multipart/form-data">

                            <label>Logo Input</label>
                            <input id="file-logo" name="logo" type="file" multiple>
                        </form>
                    </div>
                    <!--end test-->
                </div>

                <div class="modal-footer" style="margin-top:0;">

                    <button id="ccacel" type="button" class="btn btn-default" data-dismiss="modal">取消</button>

                    <button type="button" class="btn btn-primary" onclick="modifyaddress(1)">提交更改</button>

                </div>

            </div>
            <!-- /.modal-content -->

        </div>
        <!-- /.modal -->

    </div>

    <!-- 模态框（Modal） -->

    <div class="modal fade" id="coverModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

        <div class="modal-dialog">

            <div class="modal-content">

                <div class="modal-header">

                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

                    <h4 class="modal-title" id="myModalLabel">

					请输入封面背景图片地址

					</h4>

                </div>

                <div class="modal-body">

                    <input id="coverplanin" type="text" class="form-control" placeholder="http://">
                    <!--this is a upload file test!-->
                    <div>
                        <form enctype="multipart/form-data">

                            <label>Coverplan Input</label>
                            <input id="file-coverplan" name="coverplan" type="file" multiple>
                        </form>
                    </div>
                    <!--end test-->
                </div>

                <div class="modal-footer" style="margin-top:0;">

                    <button id="ccacel" type="button" class="btn btn-default" data-dismiss="modal">取消</button>

                    <button type="button" class="btn btn-primary" onclick="modifyaddress(2)">提交更改</button>

                </div>

            </div>
            <!-- /.modal-content -->

        </div>
        <!-- /.modal -->

    </div>


    <footer class="site-footer clearfix" style="margin-top:0px;">

        <section class="copyright">
            <a href="/" style="margin-bottom:0px;">
                <%=global.name%>
            </a> © 2016</section>

    </footer>
    </div>
    <script>
        var menu = new Menu;

        $('#file-avatar').fileinput({

            uploadUrl: '/api/upload/genset',
            allowedFileExtensions: ['png'],
            maxFileCount: 1,
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
        });

        $('#file-coverplan').fileinput({

            uploadUrl: '/api/upload/genset',
            allowedFileExtensions: ['png'],
            maxFileCount: 1,
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
        });

        $('#name').val('<%=global.name%>');
        $('#description').val('<%=global.discription%>');
        $('#logoin').val('<%=global.logo%>');
        $('#coverplanin').val('<%=global.coverplan%>');

        var l = '';
        var c = '';

        function modifyaddress(num) {
            if (num == 1) {
                l = $('#logoin').val();

                if (l == '' && $('#file-logo').val() != '') {
                    l = '/img/logo.png';
                }
            } else if (num == 2) {
                c = $('#coverplanin').val();

                if (c == '' && $('#file-coverplan').val() != '') {
                    c = '/img/coverplan.png';
                }
            }
        }

        function save() {
            var name = $('#name').val();
            var discription = $('#discription').val();
            var logo = l;
            var coverplan = c;

            $.ajax({

                type: "POST",

                cache: false,

                url: "/api/admin/genset",

                data: {

                    name: name,

                    discription: discription,

                    logo: logo,

                    coverplan: coverplan

                },

                success: function(msg) {

                    if (msg.status == 0) {

                        alert("修改信息成功！");
                        location.reload();

                    }

                }

            });

        }
    </script>